package com.dashboard;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;

import com.lb.jwitter.connectDatabase.ConnectPDT;
import com.opensymphony.xwork2.Action;

public class ListFilterAction {
	private ArrayList<Integer> listYearOfDKMH;
	private ArrayList<Integer> listYearOfDiemSV;
	private ArrayList<HashMap<String, String>> listKhoa;
	
	public ArrayList<HashMap<String, String>> getListKhoa() {
		return listKhoa;
	}
	public void setListKhoa(ArrayList<HashMap<String, String>> listKhoa) {
		this.listKhoa = listKhoa;
	}
	
	public ArrayList<Integer> getListYearOfDKMH() {
		return listYearOfDKMH;
	}
	public void setListYearOfDKMH(ArrayList<Integer> listYearOfDKMH) {
		this.listYearOfDKMH = listYearOfDKMH;
	}
	public ArrayList<Integer> getListYearOfDiemSV() {
		return listYearOfDiemSV;
	}
	public void setListYearOfDiemSV(ArrayList<Integer> listYearOfDiemSV) {
		this.listYearOfDiemSV = listYearOfDiemSV;
	}
	public String execute() throws Exception
	{
		ConnectPDT connectionOracle= new ConnectPDT();
		if(connectionOracle.getConnection()!=null){
			listKhoa=new ArrayList<HashMap<String, String>>();
			listYearOfDiemSV=new ArrayList<Integer>();
			listYearOfDKMH=new ArrayList<Integer>();
			String query="select DISTINCT MA_KHOA, TEN_KHOA from PDT_WEB.DM_KHOA where MA_KHOA is not null";
			HashMap<String,String> map;	
			ResultSet data=connectionOracle.getData(query);
			if(data!=null){
				while(data.next()){
					map = new HashMap<String,String>();
					String maKhoa=data.getString("MA_KHOA");
					String tenKhoa=data.getString("TEN_KHOA");
					map.put("maKhoa", maKhoa);
					map.put("tenKhoa", tenKhoa);
					listKhoa.add(map);
				}
			}
			query="select DISTINCT HK_NH from PDT_WEB.DIEM_SV order by HK_NH";
			data=connectionOracle.getData(query);
			if(data!=null){
				while(data.next()){
					String semester=data.getString("HK_NH");
					semester=semester.substring(0, 4);
					int year=Integer.parseInt(semester);
					if(!listYearOfDiemSV.contains(year)){
						listYearOfDiemSV.add(year);
					}
					
				}
			}
			query="select DISTINCT HK_NH from PDT_WEB.DKMH order by HK_NH";
			data=connectionOracle.getData(query);
			if(data!=null){
				while(data.next()){
					String semester=data.getString("HK_NH");
					semester=semester.substring(0, 4);
					int year=Integer.parseInt(semester);
					if(!listYearOfDKMH.contains(year)){
						listYearOfDKMH.add(year);
					}
					
				}
			}
			
		}
		connectionOracle.closeConnection();
		return Action.SUCCESS;

	}
}
